<%@ page import="org.json.simple.*" %> <%--json_simple_1-1.jar--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    import = "java.sql.*" %>
<%
	request.setCharacterEncoding("UTF-8");
	
	String ttext = request.getParameter("text");
	int id_a = Integer.parseInt(request.getParameter("aid"));
	
	
	String url = "jdbc:oracle:thin:@155.230.193.42:1521:oraknu";
	String user = "system";
	String pass = "DBLab012345";
	Connection con = null;
	String sql = null;
	String query = null;
	int result;

	
	try
	{
		Class.forName("oracle.jdbc.driver.OracleDriver");
		System.out.println("success");
	}
	catch(ClassNotFoundException e)
	{
		System.err.println("error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con = DriverManager.getConnection(url, user, pass);
	}
	catch(SQLException e)
	{
		System.err.println("sql error = " + e.getMessage());
		System.exit(1);
	}
	try
	{
		con.setAutoCommit(false);
		Statement stmt = con.createStatement();
		
		sql = "insert into COMMENTTABLE(tid, ttext, tdate, id_u, id_a) values(commentSequence.NEXTVAL,?,SYSTIMESTAMP,?,?)";
		
		PreparedStatement pstmt = con.prepareStatement(sql);
		
		String id = (String)session.getAttribute("logID");
		pstmt.setString(1, ttext);
		pstmt.setString(2, id);
		pstmt.setInt(3, id_a);
		
		pstmt.executeUpdate();
		
		con.commit();	
	
		stmt.close();
		con.close();
		
		JSONObject saved = new JSONObject();
		saved.put("result", "true");
		out.print(saved);
	}
	catch(Exception e)
	{
		System.err.println("sql error = " + e.getMessage());
		JSONObject saved = new JSONObject();
		saved.put("result", "false");
    saved.put("log", "로그인이 필요합니다.");
		out.print(saved);
	}
%>
